package Comunicator;

import java.io.BufferedOutputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import multiplayer.PhaseControllerOtrosClientes;

public class OutputComunicatorOtrosClientes extends Thread implements OutputComunicator{
    private String ip;
    private PhaseControllerOtrosClientes phaseControllerOtrosClientes;

    OutputComunicatorOtrosClientes(String ip, PhaseControllerOtrosClientes phaseControllerOtrosClientes) {
        this.ip = ip;
        this.phaseControllerOtrosClientes = phaseControllerOtrosClientes;
    }

    @Override
    public void run(){
        while(true){
            try {
                Socket socket = new Socket(ip, 5002);
                OutputStream oStream = socket.getOutputStream();
                ObjectOutputStream o = new ObjectOutputStream(new BufferedOutputStream(oStream));
                o.flush();
                o.writeObject(phaseControllerOtrosClientes.getBarPosition());
            } catch (Exception ex) {
                Logger.getLogger(OutputComunicatorOtrosClientes.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        }
    }    
}
